package com.ymatou.iapi.liveseller.testcase;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.liveseller.parameter.SetLiveModelBean;
import com.ymatou.iapi.liveseller.service.SetLiveModelCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.database.model.livetv.LiveModel;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
/**
*设置直播间模特
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SetLiveModel{
	private static SetLiveModelBean setlivemodelBean;
	private static SetLiveModelCall setlivemodelCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置直播间模特");
	}

	@Before
	public void caseUp() {
		setlivemodelBean=new SetLiveModelBean();
		setlivemodelCall=new SetLiveModelCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setlivemodelCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetLiveModel_001() {
		Logger.start(true,"设置直播间模特成功");
		try {
			int liveid=1;
			int userid=1;
			LiveRoomCallService.DeleteModel(userid);
			int id=LiveRoomCallService.CreateModelCall(userid, 1, 1, "nick");
			List<Integer> list=new ArrayList<Integer>();
			list.add(id);
			setlivemodelBean.setLiveId(liveid);
			setlivemodelBean.setModelIds(list);
			setlivemodelCall.setData(setlivemodelBean);
			setlivemodelCall.callService();			
			Logger.verifyEquals("200", setlivemodelCall.getString("Code"), "验证code");		
			List<LiveModel> livemodle = new LiveRoomWapper().selectLiveModelByLiveId(liveid);
			livemodle.forEach(db->{
				Logger.verifyEquals(true,list.contains(db.getModelId()), "验证tModelId");		
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SetLiveModel_002() {
		Logger.start(true,"不输入liveid失败");
		try {
			int liveid=1;
			int id=1;
			List<Integer> list=new ArrayList<Integer>();
			list.add(id);
//			setlivemodelBean.setLiveId(liveid);
			setlivemodelBean.setModelIds(list);
			setlivemodelCall.setData(setlivemodelBean);
			setlivemodelCall.callService();			
			Logger.verifyEquals("400", setlivemodelCall.getString("Code"), "验证code");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SetLiveModel_003() {
		Logger.start(true,"不输入modelIds-置空");
		try {
			int liveid=1;
			int id=1;
			List<Integer> list=new ArrayList<Integer>();
			list.add(id);
			setlivemodelBean.setLiveId(liveid);
//			setlivemodelBean.setModelIds(list);
			setlivemodelCall.setData(setlivemodelBean);
			setlivemodelCall.callService();			
			Logger.verifyEquals("200", setlivemodelCall.getString("Code"), "验证code");		
			List<LiveModel> livemodle = new LiveRoomWapper().selectLiveModelByLiveId(liveid);
			Logger.verifyEquals(0, livemodle.size(), "直播置空");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SetLiveModel_004() {
		Logger.start(true,"输入多个modelIds成功");
		try {
			int liveid=1;
			int userid=1;
			LiveRoomCallService.DeleteModel(userid);
			int id=LiveRoomCallService.CreateModelCall(userid, 1, 1, "nick");
			int id2=LiveRoomCallService.CreateModelCall(userid, 1, 2, "nick");
			List<Integer> list=new ArrayList<Integer>();
			list.add(id);
			list.add(id2);
			setlivemodelBean.setLiveId(liveid);
			setlivemodelBean.setModelIds(list);
			setlivemodelCall.setData(setlivemodelBean);
			setlivemodelCall.callService();			
			Logger.verifyEquals("200", setlivemodelCall.getString("Code"), "验证code");		
			List<LiveModel> livemodle = new LiveRoomWapper().selectLiveModelByLiveId(liveid);
			livemodle.forEach(db->{
				Logger.verifyEquals(true,list.contains(db.getModelId()), "验证tModelId");		
			});	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SetLiveModel_005() {
		Logger.start(true,"输入modelA然后改成B成功");
		try {
			int liveid=1;
			int userid=1;
			LiveRoomCallService.DeleteModel(userid);
			int id=LiveRoomCallService.CreateModelCall(userid, 1, 1, "nick");
			int id2=LiveRoomCallService.CreateModelCall(userid, 1, 2, "nick");
			List<Integer> list=new ArrayList<Integer>();
			list.add(id);
//			list.add(id2);
			setlivemodelBean.setLiveId(liveid);
			setlivemodelBean.setModelIds(list);
			setlivemodelCall.setData(setlivemodelBean);
			setlivemodelCall.callService();			
			Logger.verifyEquals("200", setlivemodelCall.getString("Code"), "验证code");		
			List<LiveModel> livemodle = new LiveRoomWapper().selectLiveModelByLiveId(liveid);
			Logger.verifyEquals(1, livemodle.size(), "验证可用列表");
			livemodle.forEach(db->{
				Logger.verifyEquals(true,list.contains(db.getModelId()), "验证tModelId");		
			});	
			
			ArrayList<Integer> list2 = new ArrayList<Integer>();
			list2.add(id2);
			setlivemodelBean.setLiveId(liveid);
			setlivemodelBean.setModelIds(list2);
			setlivemodelCall.setData(setlivemodelBean);
			setlivemodelCall.callService();			
			Logger.verifyEquals("200", setlivemodelCall.getString("Code"), "验证code");		
			livemodle = new LiveRoomWapper().selectLiveModelByLiveId(liveid);
			Logger.verifyEquals(1, livemodle.size(), "验证可用列表");
			livemodle.forEach(db->{
				Logger.verifyEquals(true,list2.contains(db.getModelId()), "验证tModelId");		
			});	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SetLiveModel_006() {
		Logger.start(true,"输入modelIds已删除失败");
		try {
			int liveid=1;
			int userid=1;
			LiveRoomCallService.DeleteModel(userid);
			int id=LiveRoomCallService.CreateModelCall(userid, 1, 1, "nick");
			LiveRoomCallService.DeleteModelById(id, userid);
			List<Integer> list=new ArrayList<Integer>();
			list.add(id);
			setlivemodelBean.setLiveId(liveid);
			setlivemodelBean.setModelIds(list);
			setlivemodelCall.setData(setlivemodelBean);
			setlivemodelCall.callService();			
			Logger.verifyEquals("200", setlivemodelCall.getString("Code"), "验证code");		
			List<LiveModel> livemodle = new LiveRoomWapper().selectLiveModelByLiveId(liveid);
			livemodle.forEach(db->{
				Logger.verifyEquals(true,list.contains(db.getModelId()), "验证tModelId");		
			});		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}